<template>
	<view class="">
		<view class="top _df _jb _ac">
			<view class="title _df _ac">
				无忧
				<view class="ml20 _df _ac" v-if="isTest" style="color: #999;margin-top: 10rpx; font-size: 28rpx;">
					正在测量<u-loading  mode="flower" size="34"></u-loading>
				</view>
			</view>
			<!-- <view class="refresh _df _ac" @click="refresh" v-if="isLogin">
				<image src="@/static/img/index/getData.png" mode=""></image>
				<span v-if="isRefresh" style="color: #999;margin-left: 10rpx;">更新数据中<u-loading mode="flower" size="34"></u-loading> </span>
			</view> -->
			<view class="people _df _jc _ac" @click="showMenu">
				<image src="@/static/img/index/icon1.png" mode=""></image>
				<view class="dot" v-if="indexData.messageCount!=0 && isLogin"></view>
			</view>
			<view class="menu" v-show="isShowMenu">
				<view class="item" @click="goEmotion" hover-class="hover">
					<span>
						异常提醒
					<view class="dot" v-if="indexData.messageCount!=0 && isLogin"></view>
					</span>
					
				</view>
				<view class="item" @click="goBt" hover-class="hover">
					连接设备
				</view>
				<!-- <view class="item" @click="goLogin" hover-class="hover">
					登录
				</view> -->
			</view>
			<!-- <u-button text="蓝牙" @click="goBt" style="margin-top: 100rpx;"></u-button> -->
			<!-- <u-button text="登录" @click="goLogin" style="margin-top: 30rpx;"></u-button> -->
		</view>
		<view class="content">
				
			<view class="emoji-box box" @click="toView('/pages/comA/emotion/emotion')">
				<view class="title mb25 _df _ac">
					<image src="@/static/img/index/icon3.png" mode=""></image>
					<span>情绪值</span>
					
					
				</view>
				<view class="more">
					<image src="@/static/img/index/icon4.png" mode=""></image>
				</view>
				<view class="emoji _df _jc">
					<image v-if="indexData.emotion_status_name=='难过'" src="@/static/img/index/emoji3.png" mode=""></image>
					<image v-else-if="indexData.emotion_status_name=='不安'" src="@/static/img/index/emoji2.png" mode=""></image>
					<image v-else-if="indexData.emotion_status_name=='平静'" src="@/static/img/index/emoji5.png" mode=""></image>
					<image v-else-if="indexData.emotion_status_name=='不错'" src="@/static/img/index/emoji1.png" mode=""></image>
					<image v-else-if="indexData.emotion_status_name=='愉悦'" src="@/static/img/index/emoji4.png" mode=""></image>
					<image v-else src="@/static/img/index/emoji1.png" mode=""></image>
				</view>
				<view class="info _df _jc _ac">
					<image src="@/static/img/index/icon2.png" mode=""></image>
					<view class="">
						当前心情：{{indexData.emotion_status_name}}
					</view>
					<view class="num">
						<!-- {{indexData.emotion}} -->
					</view>
				</view>
			</view>
			<view class="box box2" @click="toView('/pages/comA/activity/activity')">
				<view class="title-box _df _jb _ac mb40">
					<view class="title" style="color: #54BFA8;">
						<image src="@/static/img/index/icon5.png" mode=""></image>
						每日活动
					</view>
					<!-- <view class="titleR">
						今天
					</view> -->
				</view>
				<view class="left fl">
					<view class="item fl">
						<u-circle-progress
							inactive-color="#d8f7dd"
							active-color="#15CA4C" 
							:percent="percent1>100?100:percent1"
							border-width="24"
							width="140"
							duration="1000"
						 >
							
						</u-circle-progress>
					</view>
					<view class="item fl">
						<u-circle-progress
							inactive-color="#f9dfd5"
							active-color="#EB5D30" 
							:percent="percent2>100?100:percent2"
							border-width="24"
							width="140"
							duration="1000"
						 >
							
						</u-circle-progress>
					</view>
					<view class="" style="clear: both;">
						
					</view>
					<view class="item fl">
						<!-- <u-circle-progress
							inactive-color="#fdf5d7"
							active-color="#FFB000" 
							:percent="percent3>100?100:percent3"
							border-width="24"
							width="140"
							duration="1000"
						 >
							
						</u-circle-progress> -->
					</view>
					<view class="item fl">
						<u-circle-progress
							inactive-color="#d3effd"
							active-color="#47ACF7" 
							:percent="percent4>100?100:percent4"
							border-width="24"
							width="140"
							duration="1000"
						 >
							
						</u-circle-progress>
					</view>
				</view>
				<view class="right">
					<view class="item fl">
						<view class="title">
							步数
						</view>
						<view class="num">
							{{indexData.motion.stepsUser}}
						</view>
						<view class="info">
							{{indexData.motion.steps}}步
						</view>
					</view>
					<view class="item fl">
						<view class="title title1">
							消耗
						</view>
						<view class="num">
							{{(indexData.motion.heatUser / 1000).toFixed(0)}}
						</view>
						<view class="info">
							{{indexData.motion.heat / 1000}}千卡
						</view>
					</view>
					<!-- <view class="item fl">
						<view class="title title2">
							运动时长
						</view>
						<view class="num">
							{{indexData.motion.durationUser}}
						</view>
						<view class="info">
							{{indexData.motion.duration}}分钟
						</view>
					</view> -->
					<view class="item fl">
						<view class="title title3">
							距离
						</view>
						<view class="num">
							{{indexData.motion.distanceUser}}
						</view>
						<view class="info">
							{{indexData.motion.distance}}m
						</view>
					</view>
				</view>
			</view>
			<view class="box box3">
				<view class="item" v-for="(item,index) in navList" :key="index" @click="navTo(item)">
					<view class="icon">
						<image :src="item.img" mode=""></image>
					</view>
					<view class="txt">
						{{item.name}}
					</view>
				</view>
			</view>
			<view class="box box4" @click="toZhixin">
				<view class="title">
					心理评估
				</view>
				<view class="info">
					提供全面的心理评估工具，<br /> 帮助用户了解自己的心理状况和需求
				</view>
				<image class="img" src="@/static/img/index/icon12.png" mode=""></image>
			</view>
			<view class="box box5">
				<view class="item" @click="toView('/pages/comA/health/view')">
					<view class="title" style="color: #EC6560;">
						<image src="@/static/img/index/icon13.png" mode=""></image>
						心率
					</view>
					<view class="num">
						{{indexData.current_heart_rate}}次/分
					</view>
					<view class="time">
						{{time}}
					</view>
					<view class="indexchart-box">
						<l-echart ref="chart1"></l-echart>
					</view>
					<view class="info _df _jb _ac">
						<view class="">
							00:00
						</view>
						<view class="">
							23:59
						</view>
					</view>
				</view>
				<view class="item" @click="toView('/pages/comA/xueyang/xueyang')">
					<view class="title" style="color: #EC6560;">
						<image src="@/static/img/index/icon14.png" mode=""></image>
						血氧
					</view>
					<view class="num">
						{{indexData.current_blood_oxygen}}%
					</view>
					<view class="time">
						{{time}}
					</view>
					<view class="indexchart-box chart-box2 _df _ae">
						<u-line-progress :show-percent="true" active-color="#EC6560" height="46" :percent="indexData.current_blood_oxygen"></u-line-progress>
					</view>
					<view class="info _df _jb _ac">
						<view class="">
							0%
						</view>
						<view class="">
							100%
						</view>
					</view>
				</view>
				<view class="item" @click="toView('/pages/comA/sleep/sleep')">
					<view class="title" style="color: #8373F1;">
						<image src="@/static/img/index/icon15.png" mode=""></image>
						睡眠
					</view>
					<view class="num">
						{{indexData.total_sleep}}
					</view>
					<view class="time">
						{{time.slice(0,6)}}
					</view>
					<view class="indexchart-box">
						<view class="status-list">
							<view class="status-item" :class="{active1:item.isActive}" v-for="(item,index) in statusList" :key="index">
								
							</view>
						</view>
					</view>
					<view class="info _df _jb _ac">
						<view class="">
							{{sleepDown}}
						</view>
						<view class="">
							{{sleepUp}}
						</view>
					</view>
				</view>
				<view class="item" @click="toView('/pages/comA/pressure/pressure')">
					<view class="title" style="color: #61CACB;">
						<image src="@/static/img/index/icon16.png" mode=""></image>
						压力
						<!-- <span>{{pressure}}</span> -->
					</view>
					<view class="num">
						{{indexData.current_pressure}} <span style="color: #6EC856;margin-left: 10rpx;">{{indexData.current_pressure_status_name}}</span>
					</view>
					<view class="time">
						{{time}}
					</view>
					<view class="indexchart-box">
						<l-echart ref="chart2"></l-echart>
					</view>
					<view class="info _df _jb _ac">
						<view class="">
							00:00
						</view>
						<view class="">
							23:59
						</view>
					</view>
				</view>
				<!-- <view class="item" @click="toView('/pages/comA/women/women')">
					<view class="title" style="color: #EB5F8C;">
						<image src="@/static/img/index/icon18.png" mode=""></image>
						女性健康
					</view>
					<view class="num">
						经期今天结束
					</view>
					<view class="time">
						{{time}}
					</view>
					<view class="indexchart-box">
						<view class="status-list">
							<view class="status-item" :class="{active2:item.isActive}" v-for="(item,index) in statusList2" :key="index">
								
							</view>
						</view>
					</view>
					<view class="info _df _jb _ac">
						<view class="">
							9/1
						</view>
						<view class="">
							9/7
						</view>
					</view>
				</view> -->
				<view class="item" @click="toView('/pages/comA/xueya/xueya')">
					<view class="title" style="color: #F3625D;">
						<image src="@/static/img/index/icon17.png" mode=""></image>
						血压
					</view>
					<view class="num">
						{{indexData.current}} <span style="font-size: 30rpx;">mmHg</span>
					</view>
					<view class="time">
						{{time}}
					</view>
					<view class="num2">
						<u-tag size="default" :text="indexData.currentLow" :type="tagType"/>
						<u-tag size="default" class="ml10" :text="indexData.currentHight" :type="tagType2"/>
						<!-- <span :style="{'color':indexData.currentLow.includes('正常')?'#6EC856':'#F3625D'}">{{indexData.currentLow}}</span> -->
						
						<!-- <span :style="{'color':indexData.currentHight.includes('正常')?'#6EC856':'#F3625D'}">{{indexData.currentHight}}</span> -->
					</view>
					<!-- <view class="info _df _jb _ac">
						<view class="">
							偏低
						</view>
						<view class="">
							偏高
						</view>
					</view> -->
				</view>
				<view class="item" @click="toView('/pages/comA/mmol/mmol')">
					<view class="title" style="color: #EB665F;">
						<image src="@/static/img/index/icon19.png" mode=""></image>
						血糖
					</view>
					<view class="num">
						{{indexData.current_blood_sugar}} mmol/L
					</view>
					<view class="time">
						{{time}}
					</view>
					<view class="num2">
						<!-- <view class="status-list">
							<view class="status-item status-item2" :class="{active3:item.isActive}" v-for="(item,index) in statusList4" :key="index">
								
							</view>
						</view> -->
						<u-tag size="default" :text="indexData.current_blood_sugar_status_name" :type="tagType3"/>
					</view>
					<!-- <view class="info _df _jb _ac">
						<view class="">
							偏低
						</view>
						<view class="">
							偏高
						</view>
					</view> -->
				</view>
			</view>
			<send-order ref="blue" @blueBack="blueBack"></send-order>
		</view>
		<u-modal v-model="showModal" title="温馨提示" :show-cancel-button="true" confirm-text="立即前往" @confirm="toSeting" @cancel="cancel" :content="tips"></u-modal>
	</view>
	
</template>

<script>
	import config from "@/utils/config.js";
	import { BackgroundMode } from '@ionic-native/background-mode';
	import QQMapWX from "@/utils/qqMap.js";
	import * as echarts from 'echarts';
	import moment from "moment";
	import {checkOpenGPSServiceByAndroid } from '@/utils/openSettings.js';
	// 导入组件
	// const JModule = uni.requireNativePlugin('J-FrontService');
	// let hasPermission = JModule.checkNoticesPermission()
	// 返回 true 或 false
	// let res = JModule.checkIsLimit()
	// { flag: true, data: true 或 false, msg: 'success' }
	// const keep = uni.requireNativePlugin('Sj-Keep')    
	let app = getApp().globalData;
	let timer,timer2,timer3;
	export default {
		data() {
			return {
				tagType:'',
				tagType2:'',
				tagType3:'',
				//搜索
				indexNav:[],
				host:'',
				time:'',
				today:moment().format('MM月DD日'),
				isShowMenu:false,
				chartInstance: null,
				chartData:{
					series: [
					  {
						name: "步数",
						color: "#15CA4C",
						data: 0.8
					  }
					]
				},
				navList:[
					{
						name:'音乐',
						img:require('@/static/img/index/icon6.png'),
						path:'/pages/tabbar/music/index?type=0',
						pathType:1
					},
					{
						name:'正念',
						img:require('@/static/img/index/icon7.png'),
						path:'/pages/tabbar/music/index?type=1',
						pathType:1
					},
					{
						name:'冥想',
						img:require('@/static/img/index/icon8.png'),
						path:'/pages/tabbar/music/index?type=2',
						pathType:1
					},
					{
						name:'呼吸',
						img:require('@/static/img/index/icon9.png'),
						path:'/pages/comA/breathe/breathe',
						pathType:2
					},
					{
						name:'急救',
						img:require('@/static/img/index/icon10.png'),
						path:'/pages/tabbar/mine/firstaid',
						pathType:2
					}
				],
				option1:{},
				option2:{},
				statusList:[
					{
						name:'有待提高',
						isActive:false
					},
					{
						name:'一般',
						isActive:false
					},
					{
						name:'良',
						isActive:false
					},
					{
						name:'优',
						isActive:false
					}
				],
				statusList2:[
					{
						name:'有待提高',
						isActive:true
					},
					{
						name:'一般',
						isActive:false
					},
					{
						name:'良',
						isActive:false
					},
					{
						name:'良',
						isActive:false
					},
					{
						name:'良',
						isActive:false
					},
					{
						name:'良',
						isActive:false
					},
					{
						name:'优',
						isActive:false
					}
				],
				
				statusList4:[
					{
						name:'有待提高',
						isActive:true
					},
					{
						name:'一般',
						isActive:false
					},
					{
						name:'良',
						isActive:false
					},
					{
						name:'良',
						isActive:false
					},
					{
						name:'良',
						isActive:false
					},
				],
				orderDataList:[
					{
						id:0,
						name:'错误码',
						len:1,
						value:'',
						data:'',
						dataLen:0
						
					},
					{
						id:1,
						name:'总的计步值',
						type:'totalSteps',
						len:4,
						value:'',
						data:'',
						dataLen:0
					},
					{
						id:2,
						name:'总的卡路里(卡)',
						type:'totalHeat',
						len:4,
						value:'',
						data:'',
						dataLen:0
					},
					{
						id:3,
						name:'总的距离(m)',
						type:'totalDistance',
						len:4,
						value:'',
						data:'',
						dataLen:0
					},
					{
						id:4,
						name:'睡眠总时间(分钟)',
						type:'totalSleep',
						len:2,
						value:'',
						data:'',
						dataLen:0
					},
					{
						id:5,
						name:'深睡时间',
						type:'totalDeepSleep',
						len:2,
						value:'',
						data:'',
						dataLen:0
					},
					{
						id:6,
						name:'浅睡时间',
						type:'totalLightSleep',
						len:2,
						value:'',
						data:'',
						dataLen:0
					},
					{
						id:7,
						name:'当前心率',
						type:'currentHeartRate',
						len:1,
						value:'',
						data:'',
						dataLen:0
					},
					{
						id:8,
						name:'低压',
						type:'currentSs',
						len:1,
						value:'',
						data:'',
						dataLen:0
					},
					{
						id:9,
						name:'高压',
						type:'currentFz',
						len:1,
						value:'',
						data:'',
						dataLen:0
					},
					{
						id:10,
						name:'当前血氧',
						type:'currentBloodOxygen',
						len:1,
						value:'',
						data:'',
						dataLen:0
					},
					{
						id:11,
						name:'当前压力',
						type:'currentPressure',
						len:1,
						value:'',
						data:'',
						dataLen:0
					},
					{
						id:12,
						name:'当前梅脱',
						type:'currentMet',
						len:1,
						value:'',
						data:'',
						dataLen:0
					},
					{
						id:13,
						name:'当前MAI',
						type:'currentMai',
						len:1,
						value:'',
						data:'',
						dataLen:0
					},
					{
						id:14,
						name:'当前体温（显示需除以100）',
						type:'currentTemp',
						len:2,
						value:'',
						data:'',
						dataLen:0
					},
					{
						id:15,
						name:'当前血糖（显示需除以10）',
						type:'currentBloodSugar',
						len:1,
						value:'',
						data:'',
						dataLen:0
					},
					{
						id:16,
						name:'是否佩戴',
						type:'',
						len:1,
						value:'',
						data:'',
						dataLen:0
					},
				],
				orderVal:'ad0b0000',
				orderT:'0x42',
				
				watchIds:{
					
				},
				deviceId:'',
				notifyUuid:'',
				serviceId:'',
				writeId:'',
				bluedata:{},
				isJoin:false,
				dataObj:{},
				dataParams:{
					totalSteps:0,//总计步
					totalHeat:0,//总卡路里
					totalDistance:0,//总距离
					totalSleep:0,//总睡眠(分钟)
					totalDeepSleep:0,//深睡（分钟）
					totalLightSleep:0,// 浅睡（分钟）
					currentHeartRate:0,//心率（次/分钟）
					currentFz:0,//舒张压
					currentSs:0,//收缩压
					currentBloodOxygen:0,//血氧饱和度
					currentPressure:0,///压力
					currentMet:0,///梅脱
					currentMai:0,///MAI
					currentTemp:0,//温度（0.1摄氏度）
					currentBloodSugar:0,//血糖（0.1）
					iswear:0,
					createTime:null,
					longitude:'',
					latitude:'',
					address:'',
				},
				chartMin:'',
				chartMax:'',
				chartPage:{
					begin: moment().format('YYYY-MM-DD'),
					end: ""
				},
				indexData:{
					motion:{
						stepsUser:0,
						steps:0,
						heatUser:0,
						heat:0,
						durationUser:0,
						duration:0,
						distanceUser:0,
						distance:0,
					},
					current_heart_rate:0,
					current_blood_oxygen:0,
					total_sleep:0,
					current_pressure:0,
					current:0,
					current_blood_sugar:0,
				},
				percent1:0,
				percent2:0,
				percent3:0,
				percent4:0,
				sleepDown:'差',
				sleepUp:'优',
				utf8EncodedString:'',
				isNews:false,
				platform:'',
				isLogin:false,
				isRefresh:false,
				interval:0,
				isSend:false,
				pressure:0,
				pressureOrder:[
					{
						id:0,
						name:'错误码',
						len:1,
						value:'',
						data:'',
						dataLen:0
					},
					{
						id:1,
						name:'类型',
						len:1,
						value:'',
						data:'',
						dataLen:0
					},
					{
						id:1,
						name:'压力值',
						len:2,
						value:'',
						data:'',
						dataLen:0
					},
				],
				showModal:false,
				forceUpdate:false,
				tips:'为了您更好的使用和体验无忧，请您前往系统设置开启相关权限',
				healthSet:{},
				isTest:false
			};
		},
		watch: {
			isJoin(v) {
				this.isJoin = v;
			},
			isSend(v) {
				this.isSend = v;
			},
		
		},
		computed:{
			// percent1(){
			// 	let width = Number(this.indexData.motion.stepsUser / this.indexData.motion.steps).toFixed(2)
			// 	return width
			// },
		},
		onReady() {
			
		},
		onLoad() {
			this.showModal = true
			uni.setStorageSync('isTesting',false)
			const systemInfo = uni.getSystemInfoSync();
			this.platform = uni.$_getSystem();
			console.log('当前系统是',this.platform);
			if(this.platform == 'android'){
				uni.$_setPermissions()
			}
			// this.getWatch()
			// if(uni.getStorageSync('interval')){
			// 	let val = uni.getStorageSync('interval')
			// 	this.interval = Number(val) * 60 * 1000
			// 	console.log(val,'原始检测间隔')
			// }else{
			// 	this.interval = 15 * 60 * 1000
			// }
			if(uni.getStorageSync('isSet')){
				this.showModal = false
			}else{
				this.showModal = true
			}
			// this.getInterval2()
			// this.healthSet.pastFrequency = 0
			// this.editHealthSet()
			
		},
		onShow() {
			if(uni.$_getToken()){
				this.isLogin=true
			}
			
			this.getLocation()
			this.getData()
			this.isShowMenu = false
			// this.reloadchild()
			
			// this.getWatch()
			// this.getInterval()
			// this.getCurrentHeartRate()
			// this.getPressure()
			this.getInterval()
			if(this.isJoin){
				
			}
			uni.$_addAccess(this)
			// this.writeFn('da0d0000')
			// if(uni.getStorageSync('isTesting')){
			// 	this.isTest = true
			// }else{
			// 	this.isTest = false
			// }
		},
		onHide() {
			// timer = setInterval(()=>{
			// 	this.writeFn('da0d0000')
			// },1000)
			// timer2 = setInterval(()=>{
			// 	this.writeFn('da0d0000')
			// },60000)
			
			
		},
		methods: {
			
			reloadchild(){
				this.forceUpdate = !this.forceUpdate
			},
			toSeting(){
				uni.navigateTo({
					url:'/pages/tabbar/mine/keepTask'
				})
				uni.setStorageSync('isSet',true)
			},
			cancel(){
				uni.setStorageSync('isSet',false)
			},
			keepTask(){
				
			},
			startBackgroundTask() {
			      // 开始后台任务
			      JModule.startFrontService({
			          // Android生效的配置
			          title: '模拟标题',
			          content: 'XXX应用正在运行',
			          // Android新参数 mode
			          mode: 'none', // none - 普通模式，media - 后台播放无声音乐模式
			          // IOS生效的配置
			          localtion: true,    // 后台持续定位保活
			          voice: true         // 播放无声音乐保活
			      }, res => {
			          let { flag, msg } = res
					  console.log(res,9999)
			          // flag 为 true，开启成功，否则失败
			          // msg 为 成功失败的消息
			      })
			    },
			pushNewsFn(title,content,path) {   //你的处理逻辑的函数 
				let clientId = uni.getStorageSync('unipush_id')
				let that = this
				let data = {
					title:title,
					content:content,
					cid:clientId,
					payload:path,
					path:path
				}
				uni.$_post({
					url: 'https://fc-mp-d0f8413b-fe52-4bf4-a9d4-ea64a93a939d.next.bspapp.com/wuyouPush',
					that: that,
					params: data,
					success(res) {
						// console.log('发送通知',res)
					},
					fail(err) {
						// uni.showToast({
						// 	title: err.msg,
						// 	duration: 1000,
						// 	icon:'error'
						// });	
						// console.log('错误信息',err)
					},
				});
			 
			},
			convertMinutesToHours(minutes) {
			  var hours = Math.floor(minutes / 60); // 计算小时数，使用Math.floor取整
			  var remainingMinutes = minutes % 60; // 计算剩余的分钟数
			  return hours + "小时" + remainingMinutes + "分钟";
			},
			getData(){
				let that = this
				uni.$_get({
					url: "get-index-data",
					that: that,
					success(res) {
						let data = res.data;
						let sleep = res.data.total_sleep
						if(res.code == 0){
							that.indexData = data
							that.indexData.total_sleep = that.convertMinutesToHours(that.indexData.total_sleep)
							that.indexData.currentLow = that.indexData.current_status_name.split('/')[0]
							that.indexData.currentHight = that.indexData.current_status_name.split('/')[1]
							that.tagType = that.indexData.currentLow.includes('正常')?'primary':'error'
							that.tagType2 = that.indexData.currentHight.includes('正常')?'primary':'error'
							that.tagType3 = that.indexData.current_blood_sugar_status_name.includes('正常')?'primary':'error'
							if(that.indexData.newsDate){
								that.time = uni.$_momentTime(that.indexData.newsDate,'MM月DD日 HH:mm:ss')
							}
							if(data.motion.stepsUser && data.motion.steps){
								that.percent1 = Number((data.motion.stepsUser / data.motion.steps *100).toFixed(2))
							}
							if(data.motion.heatUser && data.motion.heat){
								that.percent2 = Number((data.motion.heatUser / data.motion.heat *100).toFixed(2))
							}
							if(data.motion.durationUser && data.motion.duration){
								that.percent3 = Number((data.motion.durationUser / data.motion.duration *100).toFixed(2))
							}
							if(data.motion.distanceUser && data.motion.distance){
								that.percent4 = Number((data.motion.distanceUser / data.motion.distance *100).toFixed(2))
							}
							
							if(sleep>0 && sleep<=120){
								that.sleepDown = '较差'
								that.statusList[0].isActive = true
							}else if(sleep<=240 && sleep>120){
								that.sleepDown = '差'
								that.statusList[0].isActive = true
								that.statusList[1].isActive = true
							}
							else if(sleep<=420 && sleep>240){
								that.sleepDown = '有待提高'
								that.statusList[0].isActive = true
								that.statusList[1].isActive = true
								that.statusList[2].isActive = true
							}
							else if(420<sleep){
								// that.sleepDown = '有待提高'
								that.statusList[0].isActive = true
								that.statusList[1].isActive = true
								that.statusList[2].isActive = true
								that.statusList[3].isActive = true
							}
							that.getCurrentHeartRate()
							that.getPressure()
							that.isRefresh = false
							uni.stopPullDownRefresh();
						}
					},
					fail(err) {
						uni.showToast({
							title: err.msg,
							duration: 1000,
							icon:'error'
						});	
						uni.stopPullDownRefresh();
					},
				});
			},
			getCurrentHeartRate(){
				let that = this
				uni.$_post({
					url: "getCurrentHeartRate",
					that: that,
					params: that.chartPage,
					success(res) {
						let data = res.data;
						if(res.code == 0){
							let chartData = res.data.one;
							if(res.code == 0){
								that.initChart(chartData);
							}else{
								uni.showToast({
									title: res.msg,
									duration: 2000,
									icon:'error'
								});
							}
							
						}else{
							uni.showToast({
								title: res.msg,
								duration: 1500,
								icon:'error'
							});
						}
					},
					fail(err) {
						uni.showToast({
							title: err.msg,
							duration: 1000,
							icon:'error'
						});	
					},
				});
			},
			getPressure(){
				let that = this
				uni.$_post({
					url: "getPressure",
					that: that,
					params: that.chartPage,
					success(res) {
						let data = res.data;
						if(res.code == 0){
							let chartData = res.data.one;
							if(res.code == 0){
								that.initChart2(chartData);
							}else{
								uni.showToast({
									title: res.msg,
									duration: 2000,
									icon:'error'
								});
							}
							
						}else{
							uni.showToast({
								title: res.msg,
								duration: 1500,
								icon:'error'
							});
						}
					},
					fail(err) {
						uni.showToast({
							title: err.msg,
							duration: 1000,
							icon:'error'
						});	
					},
				});
			},
			
			getLocation(){
				let that = this
				uni.getLocation({
					type: 'wgs84',
					geocode:true,
					success: function (res) {
						// console.log(res);
						// console.log('当前位置的经度：' + res.longitude);
						// console.log('当前位置的纬度：' + res.latitude);
						that.dataParams.longitude = res.longitude,
						that.dataParams.latitude = res.latitude
						// that.getAddress()
					},
					fail: function (err) {
						// checkOpenGPSServiceByAndroid()
						// uni.showModal({
						// 	title: '提示',
						// 	content: '为了您更好的体验App蓝牙功能，需要获取位置信息，请在系统设置开启定位权限。',
						// 	confirmText: '去开启',
						// 	// showCancel:false,
						// 	success: function(res) {
						// 	  if (res.confirm) {
						// 		// 用户点击确认，跳转到设置页面
								
						// 	  } else {
						// 	  }
						// 	}
						//   });
					},
				});
			},
			getAddress(){
				let that = this
				let qqmapsdk = new QQMapWX({
				  key: config.map_key,
				});
				qqmapsdk.reverseGeocoder({
				  location: {
					latitude: that.dataParams.latitude,
					longitude: that.dataParams.longitude,
				  },
				  success: (re) => {
					// console.log('经纬度解析后的信息：',re);//这里定位数据
					that.dataParams.address = re.result.formatted_addresses.standard_address
				  },
					fail:(er)=>{
						console.log(er);
					}
				});
			},

			toZhixin(){
				// uni.showToast({
				// 	title:'开发中，敬请期待···',
				// 	icon:'none'
				// })
				uni.navigateTo({
					url:'/pages/comA/zhixin/zhixin'
				})
			},
			navTo(e){
				if(e.pathType == 1){
					uni.reLaunch({
						url:e.path
					})
				}else{
					uni.navigateTo({
						url:e.path
					})
				}
			},
			getCurrentTimeHex(format) {
			    // 获取当前时间的毫秒数
				let date = new Date()
				let year = 0+date.getFullYear().toString(16)
				let year1 =year.slice(0,2)
				let year2 =year.slice(2,4)
				let month = (date.getMonth() + 1).toString(16)
				let day = date.getDate().toString(16)
				let hour = date.getHours().toString(16)
				let minute = date.getMinutes().toString(16)
				let second = date.getSeconds().toString(16)
			    if(month.length==1){
					month = 0 + (date.getMonth() + 1).toString(16)
				}else{
					month = (date.getMonth() + 1).toString(16)
				}
				if(day.length==1){
					day = 0 + day
				}else{
					day = day
				}
				if(hour.length==1){
					hour = 0 + hour
				}else{
					hour = hour
				}
				if(minute.length==1){
					minute = 0 + minute
				}else{
					minute = minute
				}if(second.length==1){
					second = 0 + second
				}else{
					second = second
				}
				
				let timeOrder = year2+year1+month+day+hour+minute+second+'00'
			    // 将毫秒数转换为16进制字符串
			 
			    return timeOrder;	
			},
			 utf8Encode(str) {
			   var utf8 = [];
			   for (var i=0; i < str.length; i++) {
			     var charcode = str.charCodeAt(i);
			     if (charcode < 0x80) utf8.push(charcode);
			     else if (charcode < 0x800) {
			       utf8.push(0xc0 | (charcode >> 6), 0x80 | (charcode & 0x3f));
			     }
			     else if (charcode < 0xd800 || charcode >= 0xe000) {
			       utf8.push(0xe0 | (charcode >> 12), 0x80 | ((charcode >> 6) & 0x3f), 0x80 | (charcode & 0x3f));
			     }
			     else {
			       i++;
			       charcode = ((charcode & 0x3ff) << 10) | (str.charCodeAt(i) & 0x3ff);
			       utf8.push(0xf0 | (charcode >> 18), 0x80 | ((charcode >> 12) & 0x3f), 0x80 | ((charcode >> 6) & 0x3f), 0x80 | (charcode & 0x3f));
			     }
			   }
			   return utf8;
			 },
			// 使用函数并打印结果
			sendOrder(){
				timer = setInterval(()=>{
					this.writeFn('da0d0000')
				},1000)
				
			},
			//字符串转utf-8
			stringToUtf8Bytes(str) {
			  const utf8Bytes = [];
			  for (let i = 0; i < str.length; i++) {
			    const codePoint = str.codePointAt(i);
			    if (codePoint <= 0x7F) {
			      // 单字节 UTF-8 编码
			      utf8Bytes.push(codePoint);
			    } else if (codePoint <= 0x7FF) {
			      // 双字节 UTF-8 编码
			      utf8Bytes.push((codePoint >> 6) | 0xC0);
			      utf8Bytes.push((codePoint & 0x3F) | 0x80);
			    } else if (codePoint <= 0xFFFF) {
			      // 三字节 UTF-8 编码
			      utf8Bytes.push((codePoint >> 12) | 0xE0);
			      utf8Bytes.push(((codePoint >> 6) & 0x3F) | 0x80);
			      utf8Bytes.push((codePoint & 0x3F) | 0x80);
			    } else {
			      // 四字节 UTF-8 编码
			      utf8Bytes.push((codePoint >> 18) | 0xF0);
			      utf8Bytes.push(((codePoint >> 12) & 0x3F) | 0x80);
			      utf8Bytes.push(((codePoint >> 6) & 0x3F) | 0x80);
			      utf8Bytes.push((codePoint & 0x3F) | 0x80);
			    }
			  }
			  return utf8Bytes;
			},
			getMonthStart(){
				let date = new Date()
				let year = '18'
				let month =uni.$_padHexString((date.getMonth() + 1).toString(16),2)
				let day =uni.$_padHexString(date.getDate().toString(16),2)
				let hour =uni.$_padHexString(date.getHours().toString(16),2)
				let minute =uni.$_padHexString(date.getMinutes().toString(16),2)
				let second =uni.$_padHexString(date.getSeconds().toString(16),2)
				
				let timeOrder = year+month+day+hour+minute+second
				// 将毫秒数转换为16进制字符串
							 
				return timeOrder;	
			},
			//消息推送
			pushNews(title,content,createTime,path){
				this.orderT = '0x38'
				// const title = "消息标题测试"; // 要转换的字符串
				let utf8Array = this.stringToUtf8Bytes(title)
				let arr = []
				
				utf8Array.map(item =>{
					let str = item.toString(16)
					arr.push(uni.$_padHexString(str,2)) 
				})
				let time = uni.$_momentTime(createTime,'MM-DD HH:mm')
				// const content = "消息内容"; // 要转换的字符串
				let con = content +'检测时间：'+ time
				let utf8Array2 = this.stringToUtf8Bytes(con)
				
				let arr2 = []
				utf8Array2.map(item =>{
					let str = item.toString(16)
					arr2.push(uni.$_padHexString(str,2)) 
				})
				let Byte1 = this.getMonthStart()//时间
				let Byte2 = uni.$_padHexString(arr.length.toString(16),2)//标题长度
				let Byte3 = uni.$_padHexString(arr2.length.toString(16),2)//消息长度
				let Byte4 = '0d'//包编号
				let Byte5 = arr.join('')//标题
				let Byte6 = arr2.join('')//内容
				let all = Byte1+Byte2+Byte3+Byte4+Byte5+Byte6
				
				// console.log(title)
				// console.log(content)
				// console.log('时间：',Byte1)
				// console.log("标题长度：",Byte2)
				// console.log("内容长度：",Byte3)
				// console.log("包编号：",Byte4)
				// console.log("标题指令：",Byte5)
				// console.log("内容指令：",Byte6)
				let dataLen = (all.length / 2).toString(16) + '00'//数据总长度
				// console.log(dataLen)
				let order = 'da38'+dataLen+Byte1+Byte2+Byte3+Byte4+Byte5+Byte6
				if(this.platform == 'ios'){
					this.pushNewsFn(title,con,path)
				}else{
					setTimeout(()=>{
						this.writeFn(order)
					},2000)
					this.pushNewsFn(title,con,path)
				}
				
			},
			backgroundMode(){
				BackgroundMode.enable();
				
				BackgroundMode.on('activate', () => {
				    console.log('后台模式已启用');
				});
			},
			refresh(){
				this.isRefresh = true
				// clearInterval(timer)
				// clearInterval(timer2)
				// setTimeout(()=>{
				// 	this.writeFn('da0d0000')
				// },1000)
				
				this.getData()
				// if(uni.getStorageSync('interval')){
				// 	let val = uni.getStorageSync('interval')
				// 	this.interval = Number(val) * 60 * 1000
				// }else{
				// 	this.interval = 15 * 60 * 1000
				// }
				// console.log(this.interval,'新的检测间隔')
				// clearInterval(timer2)
				// timer2 = setInterval(()=>{
				// 	this.orderT = '0x42'
				// 	this.writeFn('0xda4202006601')//压力
				// },this.interval)
				// timer2 = setInterval(()=>{
				// 	this.writeFn('da0d0000')
				// },this.interval)
				
			},
			getInterval(){
				let that = this
				uni.$_get({
					url: "getHeartSet",
					that: that,
					success(res) {
						if(res.code == 0){
							let _data = res.data
							that.healthSet = _data
							let newVal = Number(_data.frequency) * 60 * 1000
							let oldVal = Number(_data.pastFrequency) * 60 * 1000
							console.log(oldVal,'oldVal')
							console.log(newVal,'newVal')
							if(oldVal == 0){
								console.log('定时1')
								setTimeout(()=>{
									that.orderT = '0x42'
									uni.setStorageSync('isTesting',true)
									that.isTest = true
									that.writeFn('0xda4202006601')//压力
								},100)
								clearInterval(timer2)
								timer2 = setInterval(()=>{
									that.orderT = '0x42'
									uni.setStorageSync('isTesting',true)
									that.isTest = true
									that.writeFn('0xda4202006601')//压力
								},newVal)	
								that.healthSet.pastFrequency = _data.frequency
							}else if(newVal != oldVal){
								console.log('定时2')
								setTimeout(()=>{
									that.orderT = '0x42'
									uni.setStorageSync('isTesting',true)
									that.isTest = true
									that.writeFn('0xda4202006601')//压力
								},100)
								clearInterval(timer2)
								timer2 = setInterval(()=>{
									that.orderT = '0x42'
									uni.setStorageSync('isTesting',true)
									that.isTest = true
									that.writeFn('0xda4202006601')//压力
								},newVal)	
								that.healthSet.pastFrequency = _data.frequency
							}else{
								console.log('定时3')
								// that.healthSet.pastFrequency = 0
							}
							that.editHealthSet()
							
						}else{
							uni.showToast({
								title: res.msg,
								duration: 2000,
								icon:'error'
							});
						}
					},
					fail(err) {
						uni.showToast({
							title: err.msg,
							duration: 1000,
							icon:'error'
						});	
					},
				});
			},
			getInterval2(){
				let that = this
				uni.$_get({
					url: "getHeartSet",
					that: that,
					success(res) {
						if(res.code == 0){
							let _data = res.data
							let newVal = Number(_data.frequency) * 60 * 1000
							clearInterval(timer2)
							// timer = setInterval(()=>{
							// 	that.orderT = '0x42'
							// 	that.writeFn('0xda4202006601')//压力
							// },1000)
							
							timer2 = setInterval(()=>{
								that.orderT = '0x42'
								uni.setStorageSync('isTesting',true)
								that.isTest = true
								that.writeFn('0xda4202006601')//压力
							},newVal)	
							
						}else{
							
						}
					},
					fail(err) {
						
					},
				});
			},
			editHealthSet(){
				let that = this
				let page = {
					pastFrequency:that.healthSet.pastFrequency,//心率检测频率
					frequency:that.healthSet.frequency,//心率检测频率
					high:that.healthSet.high,//心率过高
					low:that.healthSet.low,//心率过低
					sensitiveData:that.healthSet.sensitiveData,//心率敏感值
					oxygen:that.healthSet.oxygen,//血氧过低
					relax:that.healthSet.relax,//压力提醒
					emotionData:that.healthSet.emotionData,//压力提醒
				}
				uni.$_post({
					url: "heartSetAddOrUpdate",
					that: that,
					params: page,
					success(res) {
						
						if(res.code == 0){
							
						}else{
							
						}
					},
					fail(err) {
						
					},
				});
			},
			blueBack(e,ids){
				let that = this
				if(ids){
					this.deviceId = ids.deviceId
					this.notifyUuid = ids.notifyUuid
					this.serviceId = ids.serviceId
					this.writeId = ids.writeId
				}
				this.isJoin = e
				// let strVal = uni.getStorageSync('isJoin');
				if(e){
					
					setTimeout(()=>{
						that.orderT = '0x42'
						uni.setStorageSync('isTesting',true)
						that.isTest = true
						that.writeFn('0xda4202006601')//压力
					},1000)
					setTimeout(() =>{
						this.getInterval2()
					},1000)
					
					// let val = uni.getStorageSync('interval')
					// if(uni.getStorageSync('interval')){
					// 	clearInterval(timer2)
					// 	that.interval = Number(val) * 60 * 1000
					// }else{
					// 	that.interval = 15 * 60 * 1000
					// }
					// clearInterval(timer2)
					// setTimeout(()=>{
					// 	that.orderT = '0x42'
					// 	that.writeFn('0xda4202006601')//压力
					// },100)
					// setTimeout(()=>{
					// 	timer2 = setInterval(()=>{
					// 		that.orderT = '0x42'
					// 		that.writeFn('0xda4202006601')//压力
					// 	},that.interval)
					// },900)
					// console.log(that.interval)
					// this.startNotice()
					
					
					
					
					//消息推送开关
					// setTimeout(()=>{
					// 	this.writeFn('da0c130001010101010101010101010101010101010100')
					// },1000)
					// this.pushNews()
					// console.log(arr,9999);// 输出UTF-8编码的字节序列
					//设置心率检测间隔和范围指令0x31
					// setTimeout(()=>{
					// 	this.writeFn('da3106000001173b0150')
						
					// },1000)
					//健康测量指令0x42
					// setTimeout(()=>{
					// 	this.writeFn('0xda4202006601')//压力
					// },1000)
					// setTimeout(()=>{
					// 	this.writeFn('ad170000')
					// 	// timer3 = setInterval(()=>{
					// 	// 	this.writeFn('ad170000')
					// 	// },1000)
					// },1000)
					
					// let timeOrder = 'da080800'+this.getCurrentTimeHex()
					// setTimeout(()=>{
					// 	this.dowrite(timeOrder,'0x08')
					// },1000)
					// setTimeout(()=>{
					// 	this.dowrite('da130200e001','0x13')
					// },2000)
					
				}else{
					// uni.showToast({
					// 	title:'请连接手表',
					// 	icon:'none'
					// })
					uni.setStorageSync('isTesting',false)
					this.$refs.blue.getWatch()
				}
			},
			measure(){
				this.orderT = '0x42'
				this.writeFn('0xda4202006601')//压力
			},
			writeFn(orderVal) {
				var that = this
				let crc = uni.$_getCrc_16_ibm(orderVal)
				let val = orderVal + crc
				console.log(val, '发送的指令')
				let buff = uni.$_hexStringToArrayBuffer(val)
				uni.writeBLECharacteristicValue({
					// 这里的 deviceId 需要在上面的 getBluetoothDevices 或 onBluetoothDeviceFound 接口中获取
					deviceId: that.deviceId,
					// 这里的 serviceId 需要在上面的 getBLEDeviceServices 接口中获取
					serviceId: that.serviceId,
					// 这里的 characteristicId 需要在上面的 getBLEDeviceCharacteristics 接口中获取
					characteristicId: that.writeId, //第二步写入的特征值
					// 这里的value是ArrayBuffer类型
					value: buff,
					success: function(res) {
						//此时设备已接收到你写入的数据
						console.log("写入成功", res)
						uni.onBLECharacteristicValueChange(result => {
							// console.log("监听低功耗蓝牙设备的特征值变化", result);
							if (result.value) {
								if(that.orderT == '0x0d'){
									clearInterval(timer)
									let resHex = uni.$_ab2hex(result.value)
									console.log('设备返回原始数据', resHex)
									that.dataObj = uni.$_parse_blue_response(resHex, 2)
									that.dataToArr(that.dataObj.Data,that.orderDataList)
									if(that.dataObj.Head != 'da' || that.dataObj.Cmd != "8d" ||  that.dataObj.Data.length<28) {
										// that.writeFn('da0d0000')
									}
									uni.setStorageSync('isTesting',false)
									that.isTest = false
								}else if(that.orderT == '0x42'){
									let resHex2 = uni.$_ab2hex(result.value)
									console.log('设备返回压力值', resHex2)
									that.orderT = '0x0d'
									uni.setStorageSync('isTesting',false)
									that.isTest = false
									// clearInterval(timer)
									timer = setInterval(() =>{
										that.writeFn('da0d0000')
									},1000)
									
									// if(that.dataObj.Head == 'da' && that.dataObj.Cmd == "42") {
										
									// }
									
								}
							}
						})
					},
					fail: function(err) {
						console.log(err)
						uni.hideLoading()
						that.$refs.blue.getWatch()
						uni.setStorageSync('isTesting',false)
						that.isTest = false
						// uni.showToast({
						// 	title:'请连接手表！',
						// 	icon:'none'
						// })
					},
					// complete: function() {
					// 	console.log("调用结束");
					// }
				})
			},
			
			//订阅蓝牙消息返回
			startNotice(time) {
				var that = this;
				uni.notifyBLECharacteristicValueChange({
					state: true, // 启用 notify 功能
					// 这里的 deviceId 需要已经通过 createBLEConnection 与对应设备建立链接 
					deviceId: this.deviceId,
					// 这里的 serviceId 需要在上面的 getBLEDeviceServices 接口中获取
					serviceId: this.serviceId,
					// 这里的 characteristicId 需要在上面的 getBLEDeviceCharacteristics 接口中获取
					characteristicId: this.notifyUuid, //第一步 开启监听 notityid  第二步发送指令 write
					success(res) {
						//接收蓝牙返回消息
						// that.listenValueChange()
						console.log('接收蓝牙返回消息订阅成功')
						// clearInterval(timer)
						clearInterval(timer2)
						
						// timer = setInterval(()=>{
						// 	that.orderT = '0x0d'
						// 	that.writeFn('da0d0000')
						// },1000)
						setTimeout(()=>{
							that.orderT = '0x42'
							that.writeFn('0xda4202006601')//压力
						},100)
						setTimeout(()=>{
							timer2 = setInterval(()=>{
								that.orderT = '0x42'
								that.writeFn('0xda4202006601')//压力
								// that.orderT = '0x0d'
								// that.writeFn('da0d0000')
							},that.interval)
							// that.interval
						},900)
						
					},
					fail(err) {
						console.log(err)
						uni.hideLoading()
					}
				})
			},
			//返回的数据拆分
			dataToArr(dataList,orderDataList){
				orderDataList.forEach((item,index) =>{
					if(index == 0){
						item.dataLen = item.len
						item.value  = dataList.slice(0,item.dataLen)
					}else{
						item.dataLen = orderDataList[index-1].dataLen +orderDataList[index].len
						if(item.len>=2){
							let itemArr = dataList.slice(orderDataList[index-1].dataLen,item.dataLen).reverse()
							let str = itemArr.join('')
							item.value = str
							item.data = uni.$_hex2int(str)
						}else{
							let itemArr = dataList.slice(orderDataList[index-1].dataLen,item.dataLen)
							let str = itemArr.join('')
							item.value = str
							item.data = uni.$_hex2int(str)
							
						}
					}
				})
				
				// uni.showToast({
				// 	title:'获取成功！',
				// 	icon:'success'
				// })
				if(this.orderT == '0x0d'){
					this.orderDataList = orderDataList
					this.dataParams = {
						totalSteps:this.orderDataList[1].data,//总计步
						totalHeat:this.orderDataList[2].data,//总卡路里
						totalDistance:this.orderDataList[3].data,//总距离
						totalSleep:this.orderDataList[4].data,//总睡眠(分钟)
						totalDeepSleep:this.orderDataList[5].data,//深睡（分钟）
						totalLightSleep:this.orderDataList[6].data,// 浅睡（分钟）
						currentHeartRate:this.orderDataList[7].data,//心率（次/分钟）
						currentFz:this.orderDataList[9].data,//舒张压
						currentSs:this.orderDataList[8].data,//收缩压
						currentBloodOxygen:this.orderDataList[10].data,//血氧饱和度
						currentPressure:this.orderDataList[11].data,///压力
						currentMet:this.orderDataList[12].data,///梅脱
						currentMai:this.orderDataList[13].data,///MAI
						currentTemp:this.orderDataList[14].data,//温度（0.1摄氏度）
						currentBloodSugar:(this.orderDataList[15].data / 10).toFixed(1),//血糖（0.1）
						iswear:(this.orderDataList[16].data),//是否佩戴
						createTime:null,
						longitude:this.dataParams.longitude,
						latitude:this.dataParams.latitude,
						address:this.dataParams.address,
					}
					this.addData()
				}else if(this.orderT == '0x42'){
					this.pressureOrder = orderDataList
					this.pressure = this.pressureOrder[2].data
					console.log('当前压力值：',this.pressure)
					this.orderT = '0x0d'
				}
				uni.hideLoading()
			},
			addData(data){
				let that = this
				if(this.dataParams.iswear == 0) return
				// return
				this.dataParams.createTime = moment().format('YYYY-MM-DD HH:mm:ss')
				// this.time = moment().format('MM月DD日 HH:mm')
				console.log(that.dataParams,'提交')
				uni.$_post({
					url: "addHealthData",
					that: that,
					params: that.dataParams,
					success(res) {
						console.log('数据提交成功')
						if(res.code == 0){
							let _data = res.data
							if(res.data!=null && res.data.length>0){
								_data.map(item =>{
									that.pushNews(item.title,item.content,item.createTime,item.path)
								})
							}
							clearInterval(timer)
							that.getData()
							uni.setStorageSync('isTesting',false)
							that.isTest = false
							uni.stopPullDownRefresh()
						}else{
							uni.showToast({
								title: '添加失败',
								duration: 2000,
								icon:'error'
							});
							uni.stopPullDownRefresh()
							uni.setStorageSync('isTesting',false)
						}
					},
					fail(err) {
						uni.showToast({
							title: '添加失败',
							duration: 1000,
							icon:'error'
						});	
						console.log(err)
					},
				});
				
			},
			abnormal(){
				
			},
			//连接手表
			connect(ids){
				let order = 'da0b0000'
				let crc = uni.$_getCrc_16_ibm(order)
				let val = order + crc
				console.log(val, '发送的指令')
				//指令类型
				let buff = uni.$_hexStringToArrayBuffer(val)
				uni.$_connectBluetooth(this,ids,buff)
				this.$nextTick(()=>{
					
				})
				
			},
			init() {
				
				// chart 图表实例不能存在data里
				// const chart =  this.$refs.chart1.init(this.$echarts);
				// const chart2 =  this.$refs.chart2.init(this.$echarts);
				// chart.setOption(this.option1)
				// chart2.setOption(this.option2)
			},
			initChart(chartData) {
				let that = this
				let today = moment().format('YYYY-MM-DD')
				let chartMin = uni.$_momentTime(today,'YYYY-MM-DD 00:00:00')
				let chartMax = uni.$_momentTime(today,'YYYY-MM-DD 23:59:59')
				let yData = chartData.dataList
				this.option1 = {
					grid: {
						left: '8%',
						right: '0	%',
						bottom: '0%',
						top:'4%',
						containLabel: true
					},
					xAxis: {
						type: 'time',
						splitLine: {     
							show: false   //隐藏x轴那条线
						},
						axisTick: {
							show: false   //隐藏x轴的刻度
						},
						min:chartMin,
						max:chartMax,
						axisLine: {
							show: false   
						},
						axisLabel: {
							show:false,
							showMaxLabel: true,
							boundaryGap: false,
							textStyle: {
							    color: "#ccc",
							    fontSize: '10',
							    // lineHeight: 26,
							},
						  
						  
						},
						
						
					},
					yAxis: {
						show:false,
						type: 'value',
						max:150,
						min:0,
						interval:50,
						position: 'right',
						axisLabel: {
							textStyle: {
								color: "#999",
								fontSize: '12',
							},
						},
						axisLine: {
							show: false,
							lineStyle:{
								color:"#ccc"
							}
						},
						
					},
					color: ['#ff2d3a'],
					series: [{
						// symbolSize: 4,
						showSymbol: false,
						data: yData,
						type: 'line'
					}]
				};
				this.$refs.chart1.init(this.$echarts, chart=> {
					chart.setOption(this.option1);
				});
				setTimeout(()=>{
					that.$refs.chart1.setOption(that.option1)
				},500)
			},
			initChart2(chartData) {
				let that = this
				let today = moment().format('YYYY-MM-DD')
				let chartMin = uni.$_momentTime(today,'YYYY-MM-DD 00:00:00')
				let chartMax = uni.$_momentTime(today,'YYYY-MM-DD 23:59:59')
				let yData2 = chartData.dataList
				this.option2 = {
					grid: {
						left: '8%',
						right: '0%',
						bottom: '4%',
						top:'4%',
						containLabel: true
					},
					xAxis: {
						type: 'time',
						splitLine: {     
							show: false   //隐藏x轴那条线
						},
						min:chartMin,
						max:chartMax,
						axisTick: {
							show: false   //隐藏x轴的刻度
						},
						axisLine: {
							show: false   
						},
						axisLabel: {
							show:false,
							showMaxLabel: true,
							boundaryGap: false,
							textStyle: {
							    color: "#ccc",
							    fontSize: '10',
							    // lineHeight: 26,
							},
						  
						  
						},
						
						
					},
					yAxis: {
						show:false,
						type: 'value',
						// max:50,
						// min:0,
						// interval:10,
						position: 'right',
						axisLabel: {
							textStyle: {
								color: "#999",
								fontSize: '12',
							},
						},
						axisLine: {
							show: false,
							lineStyle:{
								color:"#ccc"
							}
						},
						
					},
					color: ['#00d9b9'],
					series: [{
						symbolSize: 4,
						data: yData2,
						// showSymbol: false,
						type: 'scatter'
					}]
				};
				this.$refs.chart2.init(this.$echarts, chart=> {
					chart.setOption(this.option2);
				});
				setTimeout(()=>{
					that.$refs.chart2.setOption(that.option2)
				},500)
				
			},
			showMenu(){
				if(!uni.$_getToken()){
					uni.$_publicModal(
					  "请先登录，是否前往？",
					  function () {
					    uni.reLaunch({
					    	url: '/pages/login/login?pathType=1',
					    });
					  }
					);
				}else{
					this.isShowMenu = !this.isShowMenu
				}
				
			},
			toView(e){
				uni.navigateTo({
					url: e,
				});
			},
			goBt(){
				if(uni.getStorageSync('isTesting')){
					uni.showToast({
						title:'正在测量压力，请稍后重试',
						icon:'none',
						duration:1500
					})
				}else{
					uni.redirectTo({
						url: '/pages/comA/bluetooth/bluetooth',
					});
				}
				this.isShowMenu = false
			},	
			goLogin(){
				uni.reLaunch({
					url: '/pages/login/login?pathType=1',
				});
				// uni.navigateTo({
				// 	url: '/pages/login/login',
				// });
				this.isShowMenu = false
			},	
			goEmotion(){
				uni.navigateTo({
					url: '/pages/comA/emotion/view',
				});
				this.isShowMenu = false
			},	
			
			
		},
		onPullDownRefresh() {
			let that = this
			// that.writeFn('da0d0000')
			this.refresh()
			// this.getData()
			 //  uni.startPullDownRefresh({
				// success() {
				// 	// that.getData()
				// 	// that.getCurrentHeartRate()
				// 	// that.getPressure()
					
				// },
				// fail() {
					
				// }
				
			 //  })
		  
		}
		
	};
</script>
<style>
	page {
		background: #F2F6FE;
	}
</style>
<style lang="scss" scoped>
	.u-progress-content {
			display: flex;
			align-items: center;
			justify-content: center;
		}
		
		.u-progress-dot {
			width: 16rpx;
			height: 16rpx;
			border-radius: 50%;
			background-color: #fb9126;
		}
		
		.u-progress-info {
			font-size: 28rpx;
			padding-left: 16rpx;
			letter-spacing: 2rpx
		}
		.top{
			margin-bottom: 40rpx;
			position: sticky;
			top: 0;
			padding: 100rpx 30rpx 20rpx;
			width: 100%;
			z-index: 3;
			box-sizing: border-box;
			background: #F2F6FE url(@/static/img/index/indexTop.png) no-repeat top center / 100% auto;
			.title{
				font-size: 60rpx;
				font-family: $uni-font-family-Heavy;
				color: #000000;
			}
			.refresh{
				margin: 8rpx auto 0 20rpx;
				image{
					width: 48rpx;
					height: 48rpx;
				}
			}
			.people{
				width: 81rpx;
				height: 81rpx;
				background: #ffffff;
				border-radius: 50%;
				box-shadow: -10rpx 0rpx 30rpx 10rpx rgba(44,100,216,0.20);
				position: relative;
				image{
					height: 38rpx;
					width: 36rpx;
				}
				.dot{
					width: 18rpx;
					height: 18rpx;
					border-radius: 50%;
					position: absolute;
					top: 10rpx;
					right: 0;
					background-color: #EC0000;
					z-index: 2;
				}
			}
			.menu{
				width: 320rpx;
				background: #ffffff;
				border-radius: 24rpx;
				box-shadow: 0rpx 0rpx 20rpx 0rpx rgba(0,0,0,0.20); 
				position: fixed;
				right: 30rpx;
				top: 190rpx;
				z-index: 3;
				padding: 20rpx 0;
				box-sizing: border-box;
				.item{
					font-size: 30rpx;
					font-family: $uni-font-family-Heavy;
					color: #000000;
					height: 100rpx;
					line-height: 100rpx;
					padding: 0 20rpx 0 60rpx;
					span{
						position: relative;
						.dot{
							width: 18rpx;
							height: 18rpx;
							border-radius: 50%;
							position: absolute;
							top: 0;
							right: -10rpx;
							background-color: #EC0000;
							z-index: 2;
						}
					}
					
				}
				.hover{
					background-color: #F2F6FE;
				}
			}
		}
	.content{
		width: 100%;
		min-height: 100vh;
		padding: 0 30rpx 30rpx;
		box-sizing: border-box;
		background: #F2F6FE;
		
		.box{
			background: #ffffff;
			border-radius: 24rpx;
			margin-bottom: 30rpx;
			padding: 30rpx;
			.title{
				font-size: 30rpx;
				display: flex;
				font-family: 'PingFang-SC-Bold';
				align-items: center;
				image{
					width: 40rpx;
					height: 40rpx;
					margin-right: 10rpx;
				}
			}
		}
		.emoji-box{
			// padding: 30rpx;
			position: relative;
			.title{
				font-size: 30rpx;
				font-family: $uni-font-family-Heavy;
				color: #EC6E5C;
			}
			.more{
				position: absolute;
				top: 0;
				right: 0;
				z-index: 2;
				image{
					width: 108rpx;
					height: 68rpx;
				}
			}
			.emoji{
				margin-top: -20rpx;
				margin-bottom: 30rpx;
				height: 250rpx;
				image{
					width: 250rpx;
					height: 250rpx;
				}
			}
			.info{
				height: 64rpx;
				background: #f2f4f8;
				border-radius: 32rpx;
				font-size: 24rpx;
				color: #1F1F1F;
				image{
					width: 30rpx;
					height: 27rpx;
					margin-right: 12rpx;
				}
				.num{
					color: #EB6D5B;
					font-size: 36rpx;
					margin-left: 12rpx;
				}
			}
		}
		.box2{
			padding: 30rpx 20rpx;
			.title-box{
				padding: 0 10rpx;
			}
			.titleR{
				color: #999;
				font-size: 24rpx;
			}
			overflow: hidden;
			.left{
				margin: 30rpx 40rpx 0 0;
				.item{
					// margin-right: 10rpx;
				}
			}
			.right{
				overflow: hidden;
				.item{
					width: 50%;
					margin-bottom: 30rpx;
					.title{
						color: #15CA4C;
						font-size: 30rpx;
						font-family: $uni-font-family-Heavy;
						margin-bottom: 10rpx;
					}
					.title1{color: #EB5D30;}
					.title2{color: #FFB000;}
					.title3{color: #47ACF7;}
					.num{
						color: #212121;
						font-size: 40rpx;
						font-family: $uni-font-family-Heavy;
						margin-bottom: 14rpx;
					}
					.info{
						color: #999;
						font-size: 24rpx;
					}
				}
			}
		}
		.box3{
			padding: 38rpx 0;
			display: flex;
			.item{
				flex: 1;
				text-align: center;
				.icon{
					width: 60rpx;
					height: 60rpx;
					margin:  0 auto 15rpx;
					image{
						width: 100%;
						height: 100%;
					}
				}
				.txt{
					color: #333;
					font-size: 26rpx;
				}
			}
		}
		.box4{
			// height: 220rpx;
			background: url(../../../static/img/index/icon11.png) no-repeat center / cover;
			padding: 45rpx 60rpx 26rpx;
			box-sizing: border-box;
			border-radius: 24rpx;
			.title{
				color: #083C6C;
				font-size: 36rpx;
				font-family: $uni-font-family-Heavy;
				margin-bottom: 15rpx;
			}
			.info{
				color: #083C6C;
				opacity: 0.8;
				font-size: 20rpx;
				line-height: 30rpx;
				margin-bottom: 15rpx;
			}
			.img{
				width: 27rpx;
				height: 27rpx;
			}
		}
		.box5{
			padding: 0;
			display: grid;
			background: none;
			grid-template-columns: 1fr 1fr;
			grid-column-gap: 30rpx;
			.item{
				// width: 50%;
				margin: 0 0 30rpx 0;
				background-color: #fff;
				border-radius: 10rpx;
				padding: 30rpx 30rpx;
				.title{
					margin-bottom: 40rpx;
					font-family: 'PingFang-SC-Bold';
				}
				.num{
					color: #222;
					font-family: $uni-font-family-Heavy;
					font-size: 40rpx;
					margin-bottom: 20rpx;
				}
				.num2{
					// height: 60rpx;
					color: #EB5D30;
					font-size: 32rpx;
					font-family: $uni-font-family-Bold;
				}
				.time{
					color: #222;
					font-family: $uni-font-family-Medium;
					font-size: 24rpx;
					margin-bottom: 20rpx;
				}
				.info{
					color: #ccc;
					font-family: $uni-font-family-Medium;
					font-size: 18rpx;
					padding-top: 10rpx;
				}
				.indexchart-box{
					height: 120rpx;
					width: 100%;
					.status-list{
						display: flex;
						padding-top: 20rpx;
						.status-item{
							flex: 1;
							margin-right: 5rpx;
							background-color: #f4f4f4;
							height: 90rpx;
							border-radius: 4rpx;
							overflow: hidden;
						}
						.status-item2{
							background-color: #fee4e3;
						}
						.active1{
							background-color: #eae2ff;
						}
						.active2{
							background-color: #ffc3d7;
							position: relative;
							&:before{
								display: block;
								content: '';
								width: 100%;
								height: 4rpx;
								background-color: #fc3179;
								position: absolute;
								top: 0;
								left: 0;
								z-index: 2;
							}
						}
						.active3{
							position: relative;
							&:before{
								display: block;
								content: '';
								width: 100%;
								height: 4rpx;
								background-color: #fe5252;
								position: absolute;
								top: 0;
								left: 0;
								z-index: 2;
							}
						}
						.status-item:last-child{
							margin-right: 0;
						}
					}
				}
				.chart-box2{
					height: 100rpx;
					margin-bottom: 20rpx;
				}
				/deep/.u-progress{
					border-radius: 0 !important;
				}
			}
		}
	}
	
</style>